package com.thinkgem.jeesite.modules.sys.service;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.modules.sys.dao.ShopAddDao;
import com.thinkgem.jeesite.modules.sys.dao.TbShopVerifyDao;
import com.thinkgem.jeesite.modules.sys.dao.TbShopVerifyDao;
import com.thinkgem.jeesite.modules.sys.entity.TbMpWalletStream;
import com.thinkgem.jeesite.modules.sys.entity.TbShopVerify;
import com.thinkgem.jeesite.modules.sys.entity.TbShopVerify;
import com.thinkgem.jeesite.modules.sys.entity.User;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 店铺审核Service
 * @author huoyan403
 * @version 2016-10-29
 */
@Service
public class TbShopVerifyService {
    @Autowired
    private TbShopVerifyDao shopVerifyDao;

    public TbShopVerify get(String id) {
        return shopVerifyDao.get(id);
    }

    public List<TbShopVerify> findList(TbShopVerify TbShopVerify) {
        return shopVerifyDao.findList(TbShopVerify);
    }

    public Page<TbShopVerify> findPage(Page<TbShopVerify> page, TbShopVerify tbShopVerify) {
        //如果是代理商则根据省市来查询，如果是系统管理员则查询全部
        User curr=UserUtils.getUser();
        String roleId=shopVerifyDao.roleId(curr.getId());
        if(roleId.equals("2")){
            User user=this.ares(curr.getId());
            tbShopVerify.setProvice(user.getProvinces());
            tbShopVerify.setCity(user.getCitys());
        }
        Date date=tbShopVerify.getEndDate();
        if(date!=null){
            date.setHours(23);
            date.setMinutes(59);
            date.setSeconds(59);
        }
        tbShopVerify.setPage(page);
        List list=shopVerifyDao.findList(tbShopVerify);
        page.setList(list);
        return page;
    }
    public Page<TbMpWalletStream> mpWalletStream(Page<TbMpWalletStream> page, TbMpWalletStream tbMpWalletStream) {
        //根据用户id‘得到麻雀流水记录
        tbMpWalletStream.setPage(page);
        List list=shopVerifyDao.mpwalletStream(tbMpWalletStream);
        page.setList(list);
        return page;
    }
    public User ares(String uid){
        return shopVerifyDao.userAreas(uid);
    }

    public void save(TbShopVerify TbShopVerify) {
        shopVerifyDao.save(TbShopVerify);
    }

    public void edit(TbShopVerify TbShopVerify) {
        shopVerifyDao.update(TbShopVerify);
    }

    public void delete(TbShopVerify TbShopVerify) {
        shopVerifyDao.delete(TbShopVerify);
    }

}
